import java.util.Arrays;
import java.util.Scanner;

/**
 * @author: lwt
 * @date: 2025/7/23 20:10
 * @description:
 *
 * 选择排序
 */
public class selectSort {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[]{18,26,19,7,2};
//        for(int i = 0;i<arr.length;i++) {
//            arr[i] = sc.nextInt();
//        }
        System.out.println(Arrays.toString(arr));
        select(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void select(int[] arr) {
        int temp;
        int index;
        for (int i = 0;i<arr.length;i++){
            int min = arr[i];
            index = i;
            for (int j = i+1;j<arr.length;j++){ //遍历除首元素之外的元素
                if (arr[j]<min){   //如果存在比min小的值
                    min = arr[j];  //把该值赋给min
                    index = j;    //index存入该值下标j
                }
//                if (arr[j]<arr[i]){
//                    temp = arr[i];
//                    arr[i] = arr[j];
//                    arr[j] = temp;
                }
            //交换两个值
            temp = arr[i];
            arr[i] = arr[index];
            arr[index] = temp;
            }

        }

}
